<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="jsyName">
        <el-input
          v-model="queryParams.jsyName"
          placeholder="请输入驾驶员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="jsyIdno">
        <el-input
          v-model="queryParams.jsyIdno"
          placeholder="请输入驾驶员身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="jsyPhone">
        <el-input
          v-model="queryParams.jsyPhone"
          placeholder="请输入驾驶员电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶证" prop="jsyJszno">
        <el-input
          v-model="queryParams.jsyJszno"
          placeholder="请输入驾驶证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:jsy:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:jsy:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:jsy:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:jsy:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jsyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="驾驶员id" align="center" prop="id" />
      <el-table-column label="驾驶员姓名" align="center" prop="jsyName" />
      <el-table-column label="驾驶员生日" align="center" prop="jsyBrith" />
      <el-table-column label="驾驶员身份证" align="center" prop="jsyIdno" />
      <el-table-column label="驾驶员电话" align="center" prop="jsyPhone" />
      <el-table-column label="驾驶证号码" align="center" prop="jsyJszno" />
      <el-table-column label="从业资格证件号" align="center" prop="jsyCyzgNo" />
      <el-table-column label="入职日期" align="center" prop="jsyRzrq" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="离职日期" align="center" prop="jsyLzrq" />
      <el-table-column label="基本工资" align="center" prop="jsyJbgz" />
      <el-table-column label="个人社保" align="center" prop="jsyGrsb" />
      <el-table-column label="合同日期" align="center" prop="jsyHtrq" />
      <el-table-column label="所属基地" align="center" prop="jsySsjd" />
      <el-table-column label="从业资格类别" align="center" prop="jsyCyzgType" />
      <el-table-column label="初次发证日期" align="center" prop="jsyCcfz" />
      <el-table-column label="发证机关" align="center" prop="jsyFzjg" />
      <el-table-column label="服务单位" align="center" prop="jsyFwdw" />
      <el-table-column label="驾驶证类型" align="center" prop="jsyCardType" />
      <el-table-column label="驾驶证签发日期" align="center" prop="jsyCardDate" />
      <el-table-column label="证件到期日期" align="center" prop="jsyCardExpire" />
      <el-table-column label="住址" align="center" prop="jsyAddress" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:jsy:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:jsy:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="驾驶员姓名" prop="jsyName">
          <el-input v-model="form.jsyName" placeholder="请输入驾驶员姓名" />
        </el-form-item>
        <el-form-item label="驾驶员生日" prop="jsyBrith">
          <el-input v-model="form.jsyBrith" placeholder="请输入驾驶员生日" />
        </el-form-item>
        <el-form-item label="驾驶员身份证" prop="jsyIdno">
          <el-input v-model="form.jsyIdno" placeholder="请输入驾驶员身份证" />
        </el-form-item>
        <el-form-item label="驾驶员电话" prop="jsyPhone">
          <el-input v-model="form.jsyPhone" placeholder="请输入驾驶员电话" />
        </el-form-item>
        <el-form-item label="驾驶证号码" prop="jsyJszno">
          <el-input v-model="form.jsyJszno" placeholder="请输入驾驶证号码" />
        </el-form-item>
        <el-form-item label="从业资格证件号" prop="jsyCyzgNo">
          <el-input v-model="form.jsyCyzgNo" placeholder="请输入从业资格证件号" />
        </el-form-item>
        <el-form-item label="入职日期" prop="jsyRzrq">
          <el-input v-model="form.jsyRzrq" placeholder="请输入入职日期" />
        </el-form-item>
        <el-form-item label="离职日期" prop="jsyLzrq">
          <el-input v-model="form.jsyLzrq" placeholder="请输入离职日期" />
        </el-form-item>
        <el-form-item label="基本工资" prop="jsyJbgz">
          <el-input v-model="form.jsyJbgz" placeholder="请输入基本工资" />
        </el-form-item>
        <el-form-item label="个人社保" prop="jsyGrsb">
          <el-input v-model="form.jsyGrsb" placeholder="请输入个人社保" />
        </el-form-item>
        <el-form-item label="合同日期" prop="jsyHtrq">
          <el-input v-model="form.jsyHtrq" placeholder="请输入合同日期" />
        </el-form-item>
        <el-form-item label="所属基地" prop="jsySsjd">
          <el-input v-model="form.jsySsjd" placeholder="请输入所属基地" />
        </el-form-item>
        <el-form-item label="初次发证日期" prop="jsyCcfz">
          <el-input v-model="form.jsyCcfz" placeholder="请输入初次发证日期" />
        </el-form-item>
        <el-form-item label="发证机关" prop="jsyFzjg">
          <el-input v-model="form.jsyFzjg" placeholder="请输入发证机关" />
        </el-form-item>
        <el-form-item label="服务单位" prop="jsyFwdw">
          <el-input v-model="form.jsyFwdw" placeholder="请输入服务单位" />
        </el-form-item>
        <el-form-item label="驾驶证签发日期" prop="jsyCardDate">
          <el-input v-model="form.jsyCardDate" placeholder="请输入驾驶证签发日期" />
        </el-form-item>
        <el-form-item label="证件到期日期" prop="jsyCardExpire">
          <el-input v-model="form.jsyCardExpire" placeholder="请输入证件到期日期" />
        </el-form-item>
        <el-form-item label="住址" prop="jsyAddress">
          <el-input v-model="form.jsyAddress" placeholder="请输入住址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJsy, getJsy, delJsy, addJsy, updateJsy } from "@/api/system/jsy";

export default {
  name: "Jsy",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      jsyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jsyName: null,
        jsyBrith: null,
        jsyIdno: null,
        jsyPhone: null,
        jsyJszno: null,
        jsyCyzgNo: null,
        jsyRzrq: null,
        status: null,
        jsyLzrq: null,
        jsyJbgz: null,
        jsyGrsb: null,
        jsyHtrq: null,
        jsySsjd: null,
        jsyCyzgType: null,
        jsyCcfz: null,
        jsyFzjg: null,
        jsyFwdw: null,
        jsyCardType: null,
        jsyCardDate: null,
        jsyCardExpire: null,
        jsyAddress: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listJsy(this.queryParams).then(response => {
        this.jsyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        jsyName: null,
        jsyBrith: null,
        jsyIdno: null,
        jsyPhone: null,
        jsyJszno: null,
        jsyCyzgNo: null,
        jsyRzrq: null,
        status: null,
        jsyLzrq: null,
        jsyJbgz: null,
        jsyGrsb: null,
        jsyHtrq: null,
        jsySsjd: null,
        jsyCyzgType: null,
        jsyCcfz: null,
        jsyFzjg: null,
        jsyFwdw: null,
        jsyCardType: null,
        jsyCardDate: null,
        jsyCardExpire: null,
        jsyAddress: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getJsy(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateJsy(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJsy(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delJsy(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/jsy/export', {
        ...this.queryParams
      }, `jsy_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
